//接口统一管理模块
import request from "../utils/request";

// 引入mockjs模拟数据,
import mockRequest from "../utils/mockRequest";

// 请求首页的【轮播图数据】（模拟）
export const getSlideList = () => {
  return mockRequest({
    url: "/slide",
    method: "GET",
  });
};

// 请求首页的【楼层数据】（模拟）
export const getFloorList = () => {
  return mockRequest({
    url: "/floor",
    method: "GET",
  });
};

// 请求首页的【三级分类列表】
export const getCategoryList = () => {
  return request({
    url: "/api/product/getBaseCategoryList",
    method: "GET",
  });
};

// 请求【用户信息，需要携带token】
export const getUserInfo = () => {
  return request({
    url: "/api/user/passport/auth/getUserInfo",
    method: "GET",
  });
};

// 请求【登录】接口
export const getLogin = (loginParamsObj) => {
  return request({
    url: "/api/user/passport/login",
    method: "POST",
    data: loginParamsObj,
  });
};

// 请求【退出登录】接口
export const getLogout = () => {
  return request({
    url: "/api/user/passport/logout",
    method: "GET",
  });
};

// 请求【获取验证码】接口
export const getCode = (phone) => {
  return request({
    url: `/api/user/passport/sendCode/${phone}`,
    method: "GET",
  });
};

// 请求【注册】接口
export const getRegister = (phone, password, code) => {
  return request({
    url: "/api/user/passport/register",
    method: "POST",
    data: { phone, password, code },
  });
};

// 请求【商品搜索】接口
export const getProductSearch = (searchParams) => {
  return request({
    url: "/api/list",
    method: "POST",
    data: searchParams,
  });
};

// 请求【获取商品详情信息】接口
export const getProductDetailInfo = (id) => {
  return request({
    url: `/api/item/${id}`,
    method: "GET",
  });
};

// 请求【添加商品到购物车、对购物车中商品数量进行改动（正数是加，负数是减）】
export const getAddOrUpdateCart = (id, num) => {
  return request({
    url: `/api/cart/addToCart/${id}/${num}`,
    method: "POST",
  });
};

// 请求【获取购物车列表】接口
export const getCartList = () => {
  return request({
    url: "/api/cart/cartList",
    method: "GET",
  });
};

//请求【勾选购物车中的商品】
export const getCheckCart = (id, flag) => {
  return request({
    url: `/api/cart/checkCart/${id}/${flag}`,
    method: "GET",
  });
};

// 请求【勾选购物车中的所有选中商品】
export const getCheckAll = (skuIdList, isChecked) => {
  return request({
    url: `/api/cart/batchCheckCart/${isChecked}`,
    method: "POST",
    data: { skuIdList },
  });
};

// 请求【删除购物车中的某个商品】
export const getDeleteOne = (id) => {
  return request({
    url: `/api/cart/deleteCart/${id}`,
    method: "DELETE",
  });
};

// 请求【删除购物车中选中的多个商品】
export const getBatchDelete = (skuIdList) => {
  return request.post(`/api/cart/batchDeleteCart`, skuIdList);
};

//请求【交易信息，需要携带token】
export const getTradeInfo = () => {
  return request({
    url: "/api/order/auth/trade",
    method: "GET",
  });
};

//请求【提交订单】接口
export const getSubmitOrder = (tradeNo, paramsObj) => {
  return request({
    url: `/api/order/auth/submitOrder?tradeNo=${tradeNo}`,
    method: "POST",
    data: paramsObj,
  });
};

//请求【获取某笔订单的支付信息】接口
export const getPayInfo = (id) => {
  return request({
    url: `/api/payment/weixin/createNative/${id}`,
    method: "GET",
  });
};

//请求【获取某笔订单的支付状态】接口
export const getPayStatus = (id) => {
  return request({
    url: `/api/payment/weixin/queryPayStatus/${id}`,
    method: "GET",
  });
};

//请求【我的订单】接口
export const getMyOrderInfor = (pageNo, pageSize) => {
  return request({
    url: `/api/order/auth/${pageNo}/${pageSize}`,
    method: "GET",
  });
};

//请求【获取用户地址列表】接口

// 请求【商品列表】接口
export const getProductList = (params) => {
  return request({
    url: "/api/product/list",
    method: "GET",
    params,
  });
};
